/**
* @description: 作业详情
* @author: zhaohui
* @data:2023年6月10日
* @remark:
**/

<template>
	<view class="app-container">
		<nav-bar title="作业详情" @goBack="goBack"></nav-bar>
		<view class="content">
			<view class="information">
				<text class="content-title">计划详情</text>
				<view class="information-data">
					<view class="information-list" v-for="(item,index) in informationList" :key="index">
						<text>{{ item.title }}</text>
						<text>{{ item.name }}</text>
					</view>
				</view>
			</view>
			<view class="operational-process">
				<text class="content-title">作业过程</text>
				<view class="information-data">
					<steps-view :setpList="setpList" :active="active" @operate="stepsOperate"
						:isMyInitiate="isMyInitiate"></steps-view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import navBar from "../common/navBar.vue"
	import stepsView from "../common/stepsView.vue"
	import {
		mapGetters
	} from "vuex";
	import {
		Toast
	} from 'vant';

	export default {
		name: 'assignmentDetail',
		components: {
			navBar,
			stepsView
		},
		props: {},
		data() {
			return {
				isRefresh: false, //是否需要刷新页面
				active: "", //setps进度
				informationList: [{
					title: "计划名称",
					name: ""
				}, {
					title: "计划时间",
					name: ""
				}, {
					title: "作业负责人",
					name: ""
				}, {
					title: "作业地点",
					name: ""
				}, {
					title: "作业内容",
					name: ""
				}, ],
				setpList: [], //作业过程数据
				objId: "",
				pushParam: null, //跳转传参
				isMyInitiate: "", //是否是我发起的页面进入-1是正常可操作（待办进入）
			};
		},
		computed: {
			...mapGetters(["userData"])
		},
		watch: {},
		onLoad(option) {
			this.objId = option.id
			this.isMyInitiate = option.isMyInitiate ? option.isMyInitiate : "-1"
			this.initData()
		},
		onShow() {
			let pages = getCurrentPages();
			let currPage = pages[pages.length - 1];
			if (currPage._data.isRefresh) {
				// 重新获取数据
				this.initData() //获取列表数据
				// 每一次需要清除，否则会参数会缓存
				currPage._data.isRefresh = false
			}
		},
		methods: {
			goBack() {
				uni.navigateBack()
				// uni.navigateTo({
				// 	url: '/pages/standardizedOperation/jobList/jobList'
				// })
			},
			initData() {
				this.$apiRequest.bzhzyApi.selectWaitHandleOneStandardization({
					id: this.objId,
					userId: this.userData.userId,
					isMyInitiate: this.isMyInitiate
				}).then(res => {
					this.informationList = [{
						title: "计划名称",
						name: res.data.PLANNAME
					}, {
						title: "计划时间",
						name: res.data.PLANTIME
					}, {
						title: "作业负责人",
						name: res.data.WORKDIRECTORNAME
					}, {
						title: "作业地点",
						name: res.data.WORKADRESSNAME
					}, {
						title: "作业内容",
						name: res.data.WORKCONTENTTYPENAME
					}, ]
					this.setpList = res.data.flowMainVos
					this.pushParam = {
						PLANENDTIME: res.data.PLANENDTIME,
						PLANSTARTTIME: res.data.PLANSTARTTIME,
						OBJID: res.data.OBJID, //计划id
					}
					this.active = this.setpList.findIndex(item => item.flowName === res.data.PLANMAINSTATENAME)
				}).catch(error => {

				})

			},
			/**
			 * @param {Object} data
			 * flowState 2 已完成
			 * isMyInitiate === "-1" 待办作业页面正常进行操作，=== "1"待办作业以外页面进入只能查看已完成的页面
			 * buttonPower 会商/预演分配是否可以操作 0可以  1不可以
			 */
			stepsOperate(data) {
				this.pushParam.flowState = data.flowState //任务状态
				let message = {
					id: this.pushParam.OBJID,
					objId: data.objId,
					flowState: data.flowState,
					flowName: data.alias,
				}
				if (data.alias === "签到" && data.flowState !== "2" && this.isMyInitiate === "-1") {
					uni.navigateTo({
						url: '/pages/standardizedOperation/singIn/singIn?list=' + encodeURIComponent(JSON
							.stringify(this.pushParam))
					})
				} else if (data.alias === "签到" && data.flowState === "2") {
					uni.navigateTo({
						url: '/pages/standardizedOperation/singIn/singIn?list=' + encodeURIComponent(JSON
							.stringify(this.pushParam))
					})
				} else if (data.alias === "勘察" && data.flowState !== "2" && this.isMyInitiate === "-1") {
					//勘察执行
					uni.navigateTo({
						url: '/pages/standardizedOperation/execute/index?id=' + this.pushParam.OBJID
					})
				} else if (data.alias === "勘察" && data.flowState === "2") {
					//勘察查看
					uni.navigateTo({
						url: '/pages/standardizedOperation/executionView/executionView?id=' + this.pushParam.OBJID
					})
				} else if (data.alias === "会商分配" && data.flowState !== "2" && data.buttonPower === 0 && this
					.isMyInitiate === "-1") {
					//会商分配
					uni.navigateTo({
						url: '/pages/standardizedOperation/meetPreview/consultationAllocation?message=' +
							encodeURIComponent(JSON.stringify(message))
					})
				} else if ((data.alias === "会商分配" || data.alias === "推演分配") && data.flowState === "2") {
					//会商分配/班组推演分配-查看
					uni.navigateTo({
						url: '/pages/standardizedOperation/meetPreview/allocationDetails?message=' +
							encodeURIComponent(JSON.stringify(message))
					})
				} else if (data.alias === "推演分配" && data.flowState !== "2" && data.buttonPower === 0 && this
					.isMyInitiate === "-1") {
					//班组推演分配
					uni.navigateTo({
						url: '/pages/standardizedOperation/deductionAllocation/deductionAllocation?message=' +
							encodeURIComponent(JSON.stringify(message))
					})
				} else if (data.alias === "会商执行" && data.buttonPower === 0 && data.flowState !== "2" && this
					.isMyInitiate === "-1") {
					//会商执行-非我发起的进入
					uni.navigateTo({
						url: '/pages/standardizedOperation/consultationRehearsal/consult/negotiateExecution?message=' +
							encodeURIComponent(JSON.stringify(message))
					})
				} else if (data.alias === "会商执行" && data.flowState === "2") {
					//会商执行-查看
					uni.navigateTo({
						url: '/pages/standardizedOperation/consultationRehearsal/consult/negotiateExecution?message=' +
							encodeURIComponent(JSON.stringify(message))
					})
				} else if (data.alias === "推演执行" && data.buttonPower === 0 && data.flowState !== "2" && this
					.isMyInitiate === "-1") {
					//推演执行-非我发起的进入
					uni.navigateTo({
						url: '/pages/standardizedOperation/consultationRehearsal/consult/negotiateExecution?message=' +
							encodeURIComponent(JSON.stringify(message))
					})
				} else if (data.alias === "推演执行" && data.flowState === "2") {
					//推演执行-查看
					uni.navigateTo({
						url: '/pages/standardizedOperation/consultationRehearsal/consult/negotiateExecution?message=' +
							encodeURIComponent(JSON.stringify(message))
					})
				} else if (data.alias === "检修准备" && data.flowState !== "2" && this
					.isMyInitiate === "-1") {
					//检修准备-非我发起的进入
					uni.navigateTo({
						url: '/pages/standardizedOperation/maintenancePreparation/index?message=' +
							encodeURIComponent(JSON.stringify(message))
					})
				} else if (data.alias === "检修准备" && data.flowState === "2") {
					//检修准备-查看
					uni.navigateTo({
						url: '/pages/standardizedOperation/maintenancePreparation/index?message=' +
							encodeURIComponent(JSON.stringify(message))
					})
				} else if (data.alias === "核查更新" && data.flowState !== "2" && this.isMyInitiate === "-1") {
					//现场验收-核查更新
					uni.navigateTo({
						url: '/pages/standardizedOperation/siteAcceptance/index?message=' +
							encodeURIComponent(JSON.stringify(message))
					})
					// Toast("暂未开放此功能")
				} else if (data.alias === "人员分工" && data.flowState !== "2" && this
					.isMyInitiate === "-1") {
					//人员分工-非我发起的进入
					uni.navigateTo({
						url: '/pages/standardizedOperation/fieldImplementation/personDivision/index?message=' +
							encodeURIComponent(JSON.stringify(message))
					})
				} else if (data.alias === "人员分工" && data.flowState === "2") {
					//人员分工-查看
					uni.navigateTo({
						url: '/pages/standardizedOperation/fieldImplementation/personDivision/index?message=' +
							encodeURIComponent(JSON.stringify(message))
					})
				} else if (data.alias === "预控措施" && data.flowState !== "2" && this.isMyInitiate === "-1") {
					//危险点分析及预控措施-执行
					uni.navigateTo({
						url: '/pages/standardizedOperation/fieldImplementation/taskExecution/index?message=' +
							encodeURIComponent(JSON.stringify(message))
					})
				} else if (data.alias === "预控措施" && data.flowState === "2") {
					//危险点分析及预控措施-详情
					uni.navigateTo({
						url: '/pages/standardizedOperation/fieldImplementation/taskExecution/executionDetail?message=' +
							encodeURIComponent(JSON.stringify(message))
					})
				} else if (data.alias === "施工执行" && data.flowState !== "2" && this.isMyInitiate === "-1") {
					//施工执行
					uni.navigateTo({
						url: '/pages/standardizedOperation/fieldImplementation/construction/index?message=' +
							encodeURIComponent(JSON.stringify(message))
					})
				} else if (data.alias === "施工执行" && data.flowState === "2") {
					//施工执行-详情
					uni.navigateTo({
						url: '/pages/standardizedOperation/fieldImplementation/construction/executionDetail?message=' +
							encodeURIComponent(JSON.stringify(message))
					})
				} else if (this.isMyInitiate !== "-1") {
					Toast("该项未完成，暂不支持查看")
				} else {
					Toast("当前人员暂无权限，或等待负责人执行")
				}
			}
		}
	};
</script>

<style lang="scss" scoped>
	.app-container {
		width: 100vw;
		height: 100vh;
		background: #F2F6FA;
		overflow: hidden;

		.content {
			display: flex;
			flex-direction: column;
			box-sizing: border-box;
			overflow: scroll;
			width: 100vw;
			height: 100vh;
			padding: 0 px2vw(30);

			.information {
				width: 100%;
				height: auto;

				.information-list {
					display: flex;
					justify-content: space-between;
					border-bottom: 1px solid #E5E5E5;
					padding: px2vw(63) 0;

					text:nth-child(1) {
						font-size: px2vw(42);
						line-height: px2vw(62);
						color: #666666;
					}

					text:nth-child(2) {
						flex: 1;
						text-align: right;
						font-size: px2vw(42);
						line-height: px2vw(62);
						color: #333333;
					}
				}

				.information-list:last-child {
					border-bottom: 0px solid #E5E5E5;
				}
			}

			.operational-process {
				flex: 1;
				width: 100%;

			}

			.information-data {
				background-color: #FFFFFF;
				padding: 0 px2vw(30);
				border-radius: px2vw(20);
			}

			.content-title {
				display: block;
				height: auto;
				font-size: px2vw(40);
				font-weight: bold;
				line-height: px2vw(54);
				color: #666666;
				padding: px2vw(50) 0 px2vw(30) 0;
			}
		}


	}
</style>
